Predefined box styles
cli-boxes comes with a set of predefined box styles that can be used to wrap around text. The above code sample logs the 'single' box style to the console.
const cliBoxes = require('cli-boxes');
console.log(cliBoxes.single);
Customizable boxes
Developers can use the predefined box styles to create customizable boxes around their text. The code sample demonstrates how to create a box with padding around the text 'Hello, World!'.
const cliBoxes = require('cli-boxes');
const box = cliBoxes.single;
const text = 'Hello, World!';
const padding = 1;
const lines = text.split('\n');
const maxLength = Math.max(...lines.map(line => line.length));
const top = box.topLeft + box.horizontal.repeat(maxLength + padding * 2) + box.topRight;
const bottom = box.bottomLeft + box.horizontal.repeat(maxLength + padding * 2) + box.bottomRight;
const side = box.vertical;
console.log(top);
lines.forEach(line => {
const paddingLeft = ' '.repeat(padding);
const paddingRight = ' '.repeat(maxLength - line.length + padding);
console.log(side + paddingLeft + line + paddingRight + side);
});
console.log(bottom);